
<%@page import="src.DataAccess"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<%@page import="src.Game"%>
<%@page import="java.io.*"%>
<jsp:useBean id="game" class="src.Game" scope="application"/>


<%

    if (session.getAttribute("playerID") != null) {

        boolean flag = true;
        if ("Increase Effort".equals(request.getParameter("command"))) {
            flag = false;
            try {
                int player = Integer.parseInt(session.getAttribute("playerID").toString());
                boolean status = DataAccess.checkStatus(player);
                if (status) {
                    Game.compute(player, 1); // +1 for increase
                    response.sendRedirect("image.jsp");
                } else {
                    response.sendRedirect("notyourturn.jsp");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


        if ("Decrease Effort".equals(request.getParameter("command"))) {
            flag = false;
            try {
                int user = Integer.parseInt(session.getAttribute("playerID").toString());
                boolean status = DataAccess.checkStatus(user);
                if (status) {
                    Game.compute(user, -1); // +1 for increase
                    response.sendRedirect("image.jsp");
                } else {
                    response.sendRedirect("notyourturn.jsp");

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }


        // if increase or decrease are not clicked.
        if (flag) {
            int playerID = Integer.parseInt(session.getAttribute("playerID").toString());
            Game.compute(playerID, 0); // +1 for increase

            response.sendRedirect("image.jsp");
        }
        /*
         * try { int playerID =
         * Integer.parseInt(session.getAttribute("playerID").toString());
         * boolean status = DataAccess.checkStatus(playerID); if (!status) { //
         * Refresh only for inactive players. Game.compute(playerID, 0); // +1
         * for increase response.sendRedirect("image.jsp"); } } catch (Exception
         * e) { e.printStackTrace(); }
         *
         */
    }

%>











